<?php
/**
 * 标签添加验证类
 * User: 16
 * Date: 2018/1/25
 */
namespace app\api\validate;

use think\Validate;
use data\model\Article as ArticleModel;

class Article extends Validate
{
    protected $rule =   [
        'title'  => 'require',
        'desc'  => 'require',
        'type_id'   => 'require|typeislegal',
        'label_id'   => 'require',
        'content'  => 'require',
    ];

    protected $message  =   [
        'title.require'     => '标题不能为空',
        'desc.require'     => '简介不能为空',
        'type_id.require'      => '分类不能为空',
        'type_id.islegal'      => '分类不存在',
        'label_id.require'  =>'请选择标签',
        'content'           =>'内容不允许为空'
    ];

    protected function typeislegal($value){
        $types = ArticleModel::getArticleType();
        return array_key_exists($value,$types) ? true: false;
    }





}